/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MobilDetailForm.java
 *
 * Created on Jul 25, 2010, 2:47:06 PM
 */
package com.oi.eksekutif.ui.detail;

import com.oi.eksekutif.dao.MerkMobilDAO;
import com.oi.eksekutif.domain.MerkMobil;
import com.oi.eksekutif.domain.Mobil;
import javax.swing.DefaultComboBoxModel;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Pussy
 */
public class MobilDetailForm extends javax.swing.JPanel {

    private static final org.slf4j.Logger log = LoggerFactory.getLogger(MobilDetailForm.class);
    private MerkMobilDAO merkMobilDAO;
    private Mobil mobil;
    private boolean enabled;

    public Mobil getMobil() {
        this.mobil.setNomorMesin(nomorMesinTextField.getText());
        this.mobil.setNomorPintu(nomorPintuTextField.getText());
        this.mobil.setNomorPolisi(nomorPolisiTextField.getText());
        this.mobil.setNomorRangka(nomorRangkaTextField.getText());
        this.mobil.setTanggalArgo(tanggalArgoDateChooser.getDate());
        this.mobil.setTanggalKir(tanggalKirDateChooser.getDate());
        this.mobil.setTanggalPengawasan(tanggalPengawasanDateChooser.getDate());
        this.mobil.setTanggalStnk(tanggalStnkDateChooser.getDate());
        this.mobil.setTanggalUsaha(tanggalUsahaDateChooser.getDate());
        this.mobil.setMerkMobil((MerkMobil) merkMobilComboBox.getSelectedItem());
        this.mobil.setJumlahSetoran(Integer.parseInt(jumlahSetoranTextField.getText()));
        return mobil;
    }

    public void setMobil(Mobil mobil) {
        this.mobil = mobil;
        nomorMesinTextField.setText(this.mobil.getNomorMesin());
        nomorPintuTextField.setText(this.mobil.getNomorPintu());
        nomorPolisiTextField.setText(this.mobil.getNomorPolisi());
        nomorRangkaTextField.setText(this.mobil.getNomorRangka());
        tanggalArgoDateChooser.setDate(this.mobil.getTanggalArgo());
        tanggalKirDateChooser.setDate(this.mobil.getTanggalKir());
        tanggalPengawasanDateChooser.setDate(this.mobil.getTanggalPengawasan());
        tanggalStnkDateChooser.setDate(this.mobil.getTanggalStnk());
        tanggalUsahaDateChooser.setDate(this.mobil.getTanggalUsaha());
        merkMobilComboBox.setSelectedItem(this.mobil.getMerkMobil());
        jumlahSetoranTextField.setText(Integer.toString(this.mobil.getJumlahSetoran()));
    }

    @Override
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
        nomorMesinTextField.setEditable(enabled);
        nomorPintuTextField.setEditable(enabled);
        nomorPolisiTextField.setEditable(enabled);
        nomorRangkaTextField.setEditable(enabled);
        tanggalArgoDateChooser.setEnabled(enabled);
        tanggalKirDateChooser.setEnabled(enabled);
        tanggalPengawasanDateChooser.setEnabled(enabled);
        tanggalStnkDateChooser.setEnabled(enabled);
        tanggalUsahaDateChooser.setEnabled(enabled);
        merkMobilComboBox.setEnabled(enabled);
        jumlahSetoranTextField.setEditable(enabled);
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

    public MerkMobilDAO getMerkMobilDAO() {
        return merkMobilDAO;
    }

    public void setMerkMobilDAO(MerkMobilDAO merkMobilDAO) {
        this.merkMobilDAO = merkMobilDAO;

        if (merkMobilComboBox != null) {
            merkMobilComboBox.setModel(new DefaultComboBoxModel(merkMobilDAO.findAll().toArray()));
            log.info("MerkMobilComboBOx is Setted");
        }
    }

    /** Creates new form MobilDetailForm */
    public MobilDetailForm() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel10 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        nomorPintuTextField = new javax.swing.JTextField();
        nomorPolisiTextField = new javax.swing.JTextField();
        nomorRangkaTextField = new javax.swing.JTextField();
        nomorMesinTextField = new javax.swing.JTextField();
        merkMobilComboBox = new javax.swing.JComboBox();
        tanggalStnkDateChooser = new com.toedter.calendar.JDateChooser();
        tanggalPengawasanDateChooser = new com.toedter.calendar.JDateChooser();
        tanggalKirDateChooser = new com.toedter.calendar.JDateChooser();
        tanggalArgoDateChooser = new com.toedter.calendar.JDateChooser();
        tanggalUsahaDateChooser = new com.toedter.calendar.JDateChooser();
        jumlahSetoranTextField = new javax.swing.JFormattedTextField();
        reloadMerkMobilButton = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(659, 432));

        jLabel10.setText("Nomer Pintu :");

        jLabel6.setText("Nomer Polisi :");

        jLabel2.setText("Nomer Rangka :");

        jLabel9.setText("Nomer Mesin :");

        jLabel5.setText("Merk Mobil :");

        jLabel3.setText("Tanggal STNK :");

        jLabel4.setText("Tanggal Pengawasan :");

        jLabel8.setText("Tanggal KIR :");

        jLabel1.setText("Tanggal Argo :");

        jLabel11.setText("Tanggal Usaha :");

        jLabel7.setText("Jumlah Setoran :");

        merkMobilComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jumlahSetoranTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

        reloadMerkMobilButton.setText("Reload");
        reloadMerkMobilButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reloadMerkMobilButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel9)
                            .addComponent(jLabel2)
                            .addComponent(jLabel6)
                            .addComponent(jLabel10)
                            .addComponent(jLabel3)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel1)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(tanggalUsahaDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                                .addGap(210, 210, 210))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(tanggalArgoDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                                .addGap(210, 210, 210))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nomorPintuTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                                .addGap(229, 229, 229))
                            .addComponent(nomorPolisiTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 481, Short.MAX_VALUE)
                            .addComponent(nomorRangkaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 481, Short.MAX_VALUE)
                            .addComponent(nomorMesinTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 481, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(merkMobilComboBox, 0, 278, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(reloadMerkMobilButton)
                                .addGap(142, 142, 142))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(tanggalStnkDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                                .addGap(210, 210, 210))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(tanggalKirDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                                .addGap(210, 210, 210))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jumlahSetoranTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
                                .addGap(224, 224, 224))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tanggalPengawasanDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                        .addGap(210, 210, 210)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(nomorPintuTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(nomorPolisiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(nomorRangkaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(nomorMesinTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(merkMobilComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(reloadMerkMobilButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(tanggalStnkDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(tanggalPengawasanDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addComponent(tanggalKirDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(tanggalArgoDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11)
                    .addComponent(tanggalUsahaDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jumlahSetoranTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void reloadMerkMobilButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reloadMerkMobilButtonActionPerformed
        if (merkMobilComboBox != null) {
            merkMobilComboBox.setModel(new DefaultComboBoxModel(merkMobilDAO.findAll().toArray()));
            log.info("MerkMobilComboBOx is Setted");
        }
    }//GEN-LAST:event_reloadMerkMobilButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JFormattedTextField jumlahSetoranTextField;
    private javax.swing.JComboBox merkMobilComboBox;
    private javax.swing.JTextField nomorMesinTextField;
    private javax.swing.JTextField nomorPintuTextField;
    private javax.swing.JTextField nomorPolisiTextField;
    private javax.swing.JTextField nomorRangkaTextField;
    private javax.swing.JButton reloadMerkMobilButton;
    private com.toedter.calendar.JDateChooser tanggalArgoDateChooser;
    private com.toedter.calendar.JDateChooser tanggalKirDateChooser;
    private com.toedter.calendar.JDateChooser tanggalPengawasanDateChooser;
    private com.toedter.calendar.JDateChooser tanggalStnkDateChooser;
    private com.toedter.calendar.JDateChooser tanggalUsahaDateChooser;
    // End of variables declaration//GEN-END:variables
}
